# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 11:30:18 2020

@author: Administrator
"""

'''

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.


The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!

Example:

Input: [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6


'''

class Solution:
    def trap(self, height: List[int]) -> int:
        '''
        20200917--李运辰
        
        不太熟悉，多看几遍
        
        
        0 1 0 2 1 0 1 3 2 1 2 1

        lmax   =0 1 1
        rmax   =3 3 3
        amount =0 1 1
        total  =0 0 1
        '''
        total_w = 0
        for idx,h in enumerate(height):
            lmax = max(height[:idx+1])
            rmax = max(height[idx:])
            mount = min(lmax,rmax)
            total_w += (mount-h)
        return total_w
        